import cv2

# 检测人脸
def faceDetection(frame):
    classifier = cv2.CascadeClassifier("./haarcascades/haarcascade_smile.xml")
    faces = classifier.detectMultiScale(frame,
                                1.01,
                                5,
                                0,
                                (50,50),
                                (80,80))
    for face in faces:
        (x,y,w,h) = face
        cv2.rectangle(frame,(x,y),(x+w,y+h),color=(255,0,0),thickness=2)
    cv2.imshow("frame",frame)

if __name__ == '__main__':
    # 打开摄像头
    cap = cv2.VideoCapture(0)
    while True:
        fig,frame = cap.read()
        if fig is None:
            print("Capture No Found")
            break
        if cv2.waitKey(1) == ord(" "):
            break
        faceDetection(frame)
    cap.release()
    cv2.destroyAllWindows()